<?php
class Show360Controller extends FrontController {
	function Show360Controller(){
		parent::FrontController();
	}
	
	function config(){
		if(empty($this->id)){
			exit;
		}
		
		//防盗链功能
		$referer = $_SERVER['HTTP_REFERER'];
		
		
		$cache = get_cache_service();
		$key = 'show360_' . $this->id;
		$config = $cache->get($key);
		if(!YU_DEBUG && $config!==null){
			echo $config;
			exit;
		}
	
		$mod = new Show_360Model();
		$show360 = $mod->get_by_key($this->id);
		self::init_img_path($show360);
		$show360['serials'] = preg_replace('/,/', '', $show360['serials']);
		$this->assign('show360', $show360);
		$template_dir = ROOT_PATH . '/protected/web/' . $this->module . '/template/';
		$this->view->template_dir = $template_dir;
		$config_file = 'show360_config.' . TEMPLATE_TYPE;
		$content = file_get_contents($template_dir . $config_file);
		//压缩、加密
		$content = preg_replace(array(
			'%//.*%', //注释
			'/[\n|\t|\r]/' //空格、换行
		), '', $content);
		
		$config = $this->view->compile($content);
		
		$cache->set($key, $config);
		$callback = self::get_request_val('callback');
		if(!empty($callback)){
			echo $callback . '('.$config.')';
		}else{
			echo $config;
		}
// 		$this->display();
	}
	
	/**
	 * 初始化图片保存路径
	 * @param array $show360
	 */
	private function init_img_path(&$show360){
		switch ($show360['server']){
			case 'aliyun':
			case 'youyu':
			default:
				$show360['path'] = CACHE_URL . '/360/' . $show360['site_id'] . '/' . $show360['_id'];
		}
	}
}

?>